import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_tv_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_tv_widgets/widgets/button/kq_outline_button.dart';
import 'package:kq_flutter_tv_widgets/widgets/chart/kq_chart_line.dart';
import 'package:kq_flutter_tv_widgets/widgets/chart/kq_chart_line_model.dart';
import 'package:kq_flutter_tv_widgets/widgets/chart/kq_chart_model.dart';

class KqChartLineDemo extends StatefulWidget {
  const KqChartLineDemo({Key? key}) : super(key: key);
  @override
  State<KqChartLineDemo> createState() => _KqChartLineDemoState();
}

class _KqChartLineDemoState extends State<KqChartLineDemo> {
  List<ChartLineValue> chartList = [
    ChartLineValue(
        xValue: '周一',
        yValue: '20',
        isCountDivider: true,
        shaderColors: [
          KqThemeColors.bgBlue.withOpacity(0.8),
          KqThemeColors.bgBlue.withOpacity(0.1)
        ]),
    ChartLineValue(xValue: '周二', yValue: '40'),
    ChartLineValue(xValue: '周三', yValue: '30'),
    ChartLineValue(xValue: '周四', yValue: '60'),
    ChartLineValue(xValue: '周五', yValue: '50'),
    ChartLineValue(xValue: '周六', yValue: '90'),
    ChartLineValue(xValue: '周末', yValue: '70')
  ];
  List<ChartLineValue> chartList1 = [
    ChartLineValue(
        xValue: '周一',
        yValue: '30',
        lineColor: KqThemeColors.textYellow,
        isCountDivider: true,
        dividerColor: KqThemeColors.textYellow,
        shaderColors: [
          KqThemeColors.textYellow.withOpacity(0.8),
          KqThemeColors.textYellow.withOpacity(0.1)
        ]),
    ChartLineValue(xValue: '周二', yValue: '30'),
    ChartLineValue(xValue: '周三', yValue: '20'),
    ChartLineValue(xValue: '周四', yValue: '40'),
    ChartLineValue(xValue: '周五', yValue: '70'),
    ChartLineValue(xValue: '周六', yValue: '60'),
    ChartLineValue(xValue: '周末', yValue: '80')
  ];
  List<ChartLineValue> chartList2 = [
    ChartLineValue(
        xValue: '一月',
        yValue: '30',
        lineColor: KqThemeColors.textRed,
        shaderColors: [
          KqThemeColors.textRed.withOpacity(0.8),
          KqThemeColors.textRed.withOpacity(0.2)
        ]),
    ChartLineValue(xValue: '二月', yValue: '50'),
    ChartLineValue(xValue: '三月', yValue: '60'),
    ChartLineValue(xValue: '四月', yValue: '40'),
    ChartLineValue(xValue: '五月', yValue: '90'),
    ChartLineValue(xValue: '六月', yValue: '70'),
    ChartLineValue(xValue: '七月', yValue: '80'),
    ChartLineValue(xValue: '八月', yValue: '40'),
    ChartLineValue(xValue: '九月', yValue: '65'),
    ChartLineValue(xValue: '十月', yValue: '58'),
    ChartLineValue(xValue: '十一月', yValue: '95'),
    ChartLineValue(xValue: '十二月', yValue: '70'),
  ];

  ChartLineModel model = ChartLineModel(
    chartModel: KqChartModel(
        sizeHeight: 300.r, sizeWidth: 400.r, xRight: 30.r, isFixMaxY: true),
  );

  ChartLineModel model1 = ChartLineModel(
    chartModel: KqChartModel(
        sizeHeight: 300.r,
        sizeWidth: 410.r,
        xRight: 20.r,
        isFixMaxY: false,
        xFont: 11.sp),
  );

  List<List<ChartLineValue>> chartArr = [];
  bool isRefresh = false;

  @override
  void initState() {
    super.initState();
    model.chartModel.isCurve = true;
    // model.chartArry = [chartList, chartList1];
    model.chartModel.isShowPoint = true;
    model.chartModel.xLeft = 50.r;
    chartArr = [chartList1, chartList];

    model1.chartModel.maxY = model.chartModel.maxY = 100;
    model1.chartModel.isCurve = false;
    model1.chartModel.xLeft = 40.r;
    model1.chartModel.yBottom = 50.r;
    model1.chartModel.isShowValue = true;
  }

  @override
  Widget build(BuildContext context) {
    // print('----------------1');
    return Scaffold(
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            KqChartLine(
              chartModel: model,
              height: 300.r,
              backGroundColor: KqThemeColors.bgWhite,
              keyTag: "2",
              valueList: chartArr,
            ),
            SizedBox(height: 10.r),
            KqChartLine(
              chartModel: model1,
              valueList: [chartList2],
              keyTag: "1",
              backGroundColor: KqThemeColors.bgWhite,
            ),
            KqOutlineButton(
                title: '刷新',
                onTap: (disabled) {
                  // isRefresh = !isRefresh;
                  // chartArr = isRefresh ? [chartList] : [chartList1];
                  setState(() {});
                })
          ],
        ));
  }
}
